home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / sun / AWT / IMAGE / Image.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  4.7 KB  |  322 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.image.ImageObserver;
  7. import java.awt.image.ImageProducer;
  8. import java.util.Enumeration;
  9. import java.util.Hashtable;
  10.  
  11. public abstract class Image extends java.awt.Image {
  12.    ImageProducer source;
  13.    InputStreamImageSource src;
  14.    ImageInfoGrabber info;
  15.    private int width = -1;
  16.    private int height = -1;
  17.    private Hashtable properties;
  18.    private int availinfo;
  19.    Hashtable representations = new Hashtable();
  20.    ImageRepresentation baseIR;
  21.  
  22.    protected Image() {
  23.    }
  24.  
  25.    protected Image(Component var1, int var2, int var3) {
  26.       OffScreenImageSource var4 = new OffScreenImageSource(var1, var2, var3);
  27.       this.source = var4;
  28.       this.width = var2;
  29.       this.height = var3;
  30.       this.availinfo |= 3;
  31.       ImageRepresentation var5 = this.getImageRep(-1, -1);
  32.       this.representations.put(var2 + "x" + var3, var5);
  33.       this.representations.put("-1x-1", var5);
  34.       this.baseIR = var5;
  35.       var5.setDimensions(var2, var3);
  36.       var5.offscreenInit(var1.getBackground());
  37.       var4.setImageRep(var5);
  38.    }
  39.  
  40.    protected Image(ImageProducer var1) {
  41.       this.source = var1;
  42.       if (var1 instanceof InputStreamImageSource) {
  43.          this.src = (InputStreamImageSource)var1;
  44.       }
  45.  
  46.       this.info = new ImageInfoGrabber(this);
  47.       this.info.setupConsumer();
  48.    }
  49.  
  50.    public ImageProducer getSource() {
  51.       if (this.src != null) {
  52.          this.src.checkSecurity((Object)null, false);
  53.       }
  54.  
  55.       return this.source;
  56.    }
  57.  
  58.    protected void initGraphics(Graphics var1) {
  59.       OffScreenImageSource var2 = (OffScreenImageSource)this.source;
  60.       var1.setColor(var2.target.getForeground());
  61.       var1.setFont(var2.target.getFont());
  62.    }
  63.  
  64.    public Color getBackground() {
  65.       OffScreenImageSource var1 = (OffScreenImageSource)this.source;
  66.       return var1.target.getBackground();
  67.    }
  68.  
  69.    public int getWidth() {
  70.       if (this.src != null) {
  71.          this.src.checkSecurity((Object)null, false);
  72.       }
  73.  
  74.       if ((this.availinfo & 1) == 0) {
  75.          this.reconstruct(1);
  76.       }
  77.  
  78.       return this.width;
  79.    }
  80.  
  81.    public synchronized int getWidth(ImageObserver var1) {
  82.       if (this.src != null) {
  83.          this.src.checkSecurity((Object)null, false);
  84.       }
  85.  
  86.       if ((this.availinfo & 1) == 0) {
  87.          this.addWatcher(var1, true);
  88.          return -1;
  89.       } else {
  90.          return this.width;
  91.       }
  92.    }
  93.  
  94.    public int getHeight() {
  95.       if (this.src != null) {
  96.          this.src.checkSecurity((Object)null, false);
  97.       }
  98.  
  99.       if ((this.availinfo & 2) == 0) {
  100.          this.reconstruct(2);
  101.       }
  102.  
  103.       return this.height;
  104.    }
  105.  
  106.    public synchronized int getHeight(ImageObserver var1) {
  107.       if (this.src != null) {
  108.          this.src.checkSecurity((Object)null, false);
  109.       }
  110.  
  111.       if ((this.availinfo & 2) == 0) {
  112.          this.addWatcher(var1, true);
  113.          return -1;
  114.       } else {
  115.          return this.height;
  116.       }
  117.    }
  118.  
  119.    public Object getProperty(String var1, ImageObserver var2) {
  120.       if (this.src != null) {
  121.          this.src.checkSecurity((Object)null, false);
  122.       }
  123.  
  124.       if (this.properties == null) {
  125.          this.addWatcher(var2, true);
  126.          return null;
  127.       } else {
  128.          Object var3 = this.properties.get(var1);
  129.          if (var3 == null) {
  130.             var3 = java.awt.Image.UndefinedProperty;
  131.          }
  132.  
  133.          return var3;
  134.       }
  135.    }
  136.  
  137.    public boolean hasError() {
  138.       if (this.src != null) {
  139.          this.src.checkSecurity((Object)null, false);
  140.       }
  141.  
  142.       return (this.availinfo & 64) != 0;
  143.    }
  144.  
  145.    public int check(ImageObserver var1) {
  146.       if (this.src != null) {
  147.          this.src.checkSecurity((Object)null, false);
  148.       }
  149.  
  150.       if ((this.availinfo & 64) == 0 && (~this.availinfo & 7) != 0) {
  151.          this.addWatcher(var1, false);
  152.       }
  153.  
  154.       return this.availinfo;
  155.    }
  156.  
  157.    public void preload(ImageObserver var1) {
  158.       if (this.src != null) {
  159.          this.src.checkSecurity((Object)null, false);
  160.       }
  161.  
  162.       if ((this.availinfo & 32) == 0) {
  163.          this.addWatcher(var1, true);
  164.       }
  165.  
  166.    }
  167.  
  168.    private synchronized void addWatcher(ImageObserver var1, boolean var2) {
  169.       if ((this.availinfo & 64) != 0) {
  170.          if (var1 != null) {
  171.             var1.imageUpdate(this, 192, -1, -1, -1, -1);
  172.          }
  173.  
  174.       } else {
  175.          if (this.info == null) {
  176.             this.info = new ImageInfoGrabber(this);
  177.             this.info.setupConsumer();
  178.          }
  179.  
  180.          this.info.addWatcher(var1);
  181.          if (var2) {
  182.             this.info.getInfo();
  183.          }
  184.  
  185.       }
  186.    }
  187.  
  188.    private synchronized void reconstruct(int var1) {
  189.       if ((var1 & ~this.availinfo) != 0) {
  190.          if ((this.availinfo & 64) != 0) {
  191.             return;
  192.          }
  193.  
  194.          if (this.info == null) {
  195.             this.info = new ImageInfoGrabber(this);
  196.          }
  197.  
  198.          this.info.getInfo();
  199.  
  200.          while((var1 & ~this.availinfo) != 0) {
  201.             try {
  202.                this.wait();
  203.             } catch (InterruptedException var2) {
  204.                Thread.currentThread().interrupt();
  205.                return;
  206.             }
  207.  
  208.             if ((this.availinfo & 64) != 0) {
  209.                return;
  210.             }
  211.          }
  212.       }
  213.  
  214.    }
  215.  
  216.    synchronized void addInfo(int var1) {
  217.       this.availinfo |= var1;
  218.       this.notifyAll();
  219.       if ((~this.availinfo & 7) == 0) {
  220.          this.info.stopInfo();
  221.       }
  222.  
  223.    }
  224.  
  225.    void setDimensions(int var1, int var2) {
  226.       this.width = var1;
  227.       this.height = var2;
  228.       this.addInfo(3);
  229.    }
  230.  
  231.    void setProperties(Hashtable var1) {
  232.       if (var1 == null) {
  233.          var1 = new Hashtable();
  234.       }
  235.  
  236.       this.properties = var1;
  237.       this.addInfo(4);
  238.    }
  239.  
  240.    synchronized void infoDone(int var1) {
  241.       if (var1 != 1 && (~this.availinfo & 3) == 0) {
  242.          if ((this.availinfo & 4) == 0) {
  243.             this.setProperties((Hashtable)null);
  244.          }
  245.  
  246.       } else {
  247.          this.addInfo(64);
  248.       }
  249.    }
  250.  
  251.    public void flush() {
  252.       if (this.src != null) {
  253.          this.src.checkSecurity((Object)null, false);
  254.       }
  255.  
  256.       if (!(this.source instanceof OffScreenImageSource)) {
  257.          synchronized(this){}
  258.  
  259.          Enumeration var1;
  260.          try {
  261.             this.availinfo &= -65;
  262.             var1 = this.representations.elements();
  263.             this.representations = new Hashtable();
  264.             this.baseIR = null;
  265.             if (this.source instanceof InputStreamImageSource) {
  266.                ((InputStreamImageSource)this.source).flush();
  267.             }
  268.          } catch (Throwable var4) {
  269.             throw var4;
  270.          }
  271.  
  272.          while(var1.hasMoreElements()) {
  273.             ImageRepresentation var2 = (ImageRepresentation)var1.nextElement();
  274.             var2.abort();
  275.          }
  276.       }
  277.  
  278.    }
  279.  
  280.    protected ImageRepresentation getImageRep(int var1, int var2) {
  281.       if (this.src != null) {
  282.          this.src.checkSecurity((Object)null, false);
  283.       }
  284.  
  285.       String var3;
  286.       if (var1 == -1 && var2 == -1) {
  287.          if (this.baseIR != null) {
  288.             return this.baseIR;
  289.          }
  290.  
  291.          var3 = "-1x-1";
  292.       } else {
  293.          var3 = var1 + "x" + var2;
  294.       }
  295.  
  296.       ImageRepresentation var4 = (ImageRepresentation)this.representations.get(var3);
  297.       if (var4 == null) {
  298.          synchronized(this){}
  299.  
  300.          try {
  301.             var4 = (ImageRepresentation)this.representations.get(var3);
  302.             if (var4 == null) {
  303.                var4 = new ImageRepresentation(this, var1, var2, 0);
  304.                if (this.source instanceof OffScreenImageSource) {
  305.                   var4.offscreen = true;
  306.                } else {
  307.                   this.representations.put(var3, var4);
  308.                }
  309.  
  310.                if (var1 == -1 && var2 == -1) {
  311.                   this.baseIR = var4;
  312.                }
  313.             }
  314.          } catch (Throwable var7) {
  315.             throw var7;
  316.          }
  317.       }
  318.  
  319.       return var4;
  320.    }
  321. }
  322.